package com.ruoyi.jwxt.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.jwxt.service.IJwxtLabSchedulingService;
import com.ruoyi.jwxt.utility.JwxtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jwxt.domain.PO.JwxtStudentApplication;
import com.ruoyi.jwxt.service.IJwxtStudentApplicationService;

/**
 * 学生实验课申请登记Controller
 * @author ruoyi
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/jwxt/stu_application")
public class JwxtStudentApplicationController extends BaseController
{
    @Autowired
    private IJwxtStudentApplicationService jwxtStudentExperimentApplicationService;

    @Autowired
    private IJwxtLabSchedulingService jwxtLabSchedulingService;

    /**
     * 查询学生实验课申请登记列表
     */
    @PreAuthorize("@ss.hasPermi('jwxt:stu_application:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwxtStudentApplication jwxtStudentExperimentApplication)
    {
        startPage();
        List<JwxtStudentApplication> list = jwxtStudentExperimentApplicationService.select(jwxtStudentExperimentApplication);
        list=JwxtUtils.stuFilterByUser(list);
        return getDataTable(list);
    }

    /**
     * 导出学生实验课申请登记列表
     */
    @PreAuthorize("@ss.hasPermi('jwxt:stu_application:export')")
    @Log(title = "学生实验课申请登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwxtStudentApplication jwxtStudentExperimentApplication)
    {
        List<JwxtStudentApplication> list = jwxtStudentExperimentApplicationService.select(jwxtStudentExperimentApplication);
        list=JwxtUtils.stuFilterByUser(list);
        ExcelUtil<JwxtStudentApplication> util = new ExcelUtil<JwxtStudentApplication>(JwxtStudentApplication.class);
        util.exportExcel(response, list, "学生实验课申请登记数据");
    }

    /**
     * 获取学生实验课申请登记详细信息
     */
    @PreAuthorize("@ss.hasPermi('jwxt:stu_application:query')")
    @GetMapping(value = "/{applicationId}")
    public AjaxResult getInfo(@PathVariable("applicationId") Long applicationId)
    {
        return success(jwxtStudentExperimentApplicationService.select(applicationId));
    }

    /**
     * 新增学生实验课申请登记
     */
    @PreAuthorize("@ss.hasPermi('jwxt:stu_application:add')")
    @Log(title = "学生实验课申请登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwxtStudentApplication jwxtStudentExperimentApplication)
    {
        return toAjax(jwxtStudentExperimentApplicationService.insert(jwxtStudentExperimentApplication));
    }

    /**
     * 修改学生实验课申请登记
     */
    @PreAuthorize("@ss.hasPermi('jwxt:stu_application:edit')")
    @Log(title = "学生实验课申请登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwxtStudentApplication jwxtStudentExperimentApplication)
    {
        return toAjax(jwxtStudentExperimentApplicationService.update(jwxtStudentExperimentApplication));
    }

    /**
     * 删除学生实验课申请登记
     */
    @PreAuthorize("@ss.hasPermi('jwxt:stu_application:remove')")
    @Log(title = "学生实验课申请登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{applicationIds}")
    public AjaxResult remove(@PathVariable Long[] applicationIds)
    {
        return toAjax(jwxtStudentExperimentApplicationService.delete(applicationIds));
    }


    @Log(title = "学生实验课申请登记", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('jwxt:stu_application:check')")
    @PostMapping("/pass")
    public AjaxResult pass(@RequestBody JwxtStudentApplication jwxtStudentExperimentApplication)
    {
        return toAjax(jwxtLabSchedulingService.accept(jwxtStudentExperimentApplication));
    }
    @Log(title = "学生实验课申请登记", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('jwxt:stu_application:check')")
    @PostMapping ( "/reject")
    public AjaxResult reject(@RequestBody JwxtStudentApplication stu)
    {
        return toAjax(jwxtLabSchedulingService.reject(stu));
    }

    @Log(title = "学生实验课申请登记", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('jwxt:stu_application:confirm')")
    @PostMapping ( "/confirm")
    public AjaxResult used(@RequestBody JwxtStudentApplication stu)
    {
        return toAjax(jwxtStudentExperimentApplicationService.confirm(stu));
    }
}
